<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <jsp:include page="../common.jsp"></jsp:include>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="productName" lay-verify="required" lay-reqtext="菜单名称不能为空"  value="${productName}" class="layui-input">
            <tip>填写自己管理账号的呢称。</tip>
        </div>
    </div>

    <input style="display: none" type="text" name="id" value="${id}">
    <div class="layui-form-item">
        <label class="layui-form-label required">商品描述</label>
        <div class="layui-input-block">
            <input type="text" name="description" lay-verify="required" lay-reqtext="商品描述不能为空" placeholder="请输入商品描述" value="${description}" class="layui-input">
            <tip>填写自己管理账号的商品描述。</tip>
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label required">价格</label>
        <div class="layui-input-block">
            <input type="text" name="price" lay-verify="required" lay-reqtext="商品价格不能为空" placeholder="请输入商品价格" value="${price}" class="layui-input">
            <tip>填写自己商品的价格。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-block">
            <select name="status">
                <option value="0" ${status==0?'selected':''}>上架中</option>
                <option value="1" ${status==1?'selected':''}>已下架</option>
                <option value="2" ${status==2?'selected':''}>已出售</option>
                <option value="-1" ${status==-1?'selected':''}>已删除</option>
            </select>
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'

            }, function () {
                console.log(data.field)
                $.ajax({
                    url: SITE_BASE_PATH + '/product/updateProduct.do',
                    data:data.field,
                    success: function (data) {
                        alert("success");

                    },
                    error: function (data) {
                        alert("error")
                    }
                });

                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            });

            return false;
        });

    });
</script>
</body>
</html>
